/*package vn.mobiistar.videoapp.loader;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;

import org.json.JSONObject;

import vn.mobiistar.videoapp.other.Define;
import vn.mobiistar.videoapp.other.Video;
import android.content.Context;
import android.util.Log;

public class AutocompleteLoader extends BaseLoader {

	// type = 1: get new video
	// type = 2: get mostview
	// type = 3: get video by catid
	public int mType;
	public String mUrl;
	public String mKeyword = " ";
	
	public int mPage;
	public boolean mNeedNextPage;
	
	public AutocompleteLoader(Context context) {
		super(context);
		setType(Define.BLOCK_TYPE_NEW);
	}
	public int getType() {
		return mType;
	}
	public void setCateId(int mCateId) {
		this.mCateId = mCateId;
	}
	public void setType(int type) {
		mType = type;
	}
	public void setKeyword(String keyword) {
		try {
			this.mKeyword = URLEncoder.encode(keyword, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			Log.e("VideoLoader",e.getMessage());
		}
	}
	@Override
	protected BaseResult getResultInstance() {
		return new Result();
	}
	
	// tra ve mot doi tuong
	// xac dinh request
	@Override
	protected UpdateTask getUpdateTask() {
		return new VideoUpdateTask();
	}

	@Override
	protected BaseResult parseResult(JSONObject paramJSONObject,
			BaseResult result) throws Exception {
		Result localResult = (Result) result;
		localResult.mVideo = Video.valueOf(paramJSONObject);
		return localResult;
	}

	// update task
	private class VideoUpdateTask extends BaseLoader.UpdateTask {

		private boolean mIsAppend;

		@Override
		protected Request getRequest() {
			int offset = mPage * Define.BLOCK_INITLOAD_QUAN;
			switch(AutocompleteLoader.this.getType()){
			case Define.BLOCK_TYPE_NEW:
				mUrl = Define.VIDEOLOADER_URL + String.valueOf(mType)
				+ "/quanlity/" + Define.BLOCK_INITLOAD_QUAN + "/offset/"
				+ offset;
				Log.v("url",mUrl);
				return new Request(mUrl);
			case Define.BLOCK_TYPE_MOSTVIEW:
				mUrl = Define.VIDEOLOADER_URL + String.valueOf(mType)
				+ "/quanlity/" + Define.BLOCK_INITLOAD_QUAN + "/offset/"
				+ offset;
				Log.v("url",mUrl);
				return new Request(mUrl);
			case Define.BLOCK_TYPE_KEYWORD:
				mUrl = Define.VIDEOLOADER_URL + String.valueOf(mType)
				+ "/quanlity/" + Define.BLOCK_INITLOAD_QUAN + "/offset/"
				+ offset +"/keyword/"+mKeyword;
				Log.v("url",mUrl);
				return new Request(mUrl);
			case Define.SERVICE_GET_VIDEOOFCATE:
				mUrl = Define.VIDEOLOADER_URL + String.valueOf(mType)
				+ "/quanlity/" + Define.BLOCK_INITLOAD_QUAN + "/offset/"
				+ offset +"/catid/"+mCateId;
				Log.v("url",mUrl);
				return new Request(mUrl);
			default:
				break;
			}
			return null;
		}
		protected BaseResult onDataLoaded(BaseResult oldresult, BaseResult newresult){
			BaseResult localResult = null;
			if(newresult != null && (((Result)newresult).mVideo != null) && (!((Result)newresult).mVideo.isEmpty())){
				AutocompleteLoader.this.mNeedNextPage = true;
				localResult = newresult;
				mResult = newresult.shallowClone();
				if(((AutocompleteLoader.Result)oldresult).mVideo != null && ((AutocompleteLoader.Result)newresult).mVideo != null) 
				if(((AutocompleteLoader.Result)oldresult).mVideo.size() >0 && ((AutocompleteLoader.Result)newresult).mVideo.size() >0){
					localResult = merge((AutocompleteLoader.Result)oldresult, (AutocompleteLoader.Result)newresult);
				}
				return localResult;
			}
			return newresult;
		}

		private AutocompleteLoader.Result merge(AutocompleteLoader.Result oldresult, AutocompleteLoader.Result newresult){
			AutocompleteLoader.Result localResult = new AutocompleteLoader.Result();
			localResult.mVideo = new ArrayList<Video>();    
			if (oldresult != null)
				localResult.mVideo.addAll(oldresult.mVideo);
			if (newresult != null)
				localResult.mVideo.addAll(newresult.mVideo);
			return localResult;
		}
	}

	// Result
	public static final class Result extends BaseResult {
		public ArrayList<Video> mVideo;
		protected int getCount() {
			int count = 0;
			if (this.mVideo != null)
				count = this.mVideo.size();
			return count;
		}
		public BaseResult shallowClone() {
			Result localResult = new Result();
			localResult.mVideo = this.mVideo;
			return localResult;
		}
	}
	@Override
	public void reload() {
		if (!isLoading())
		{
			this.mPage = 0;
			this.mNeedNextPage = false;
			super.reload();
		}
	}


	public void nextPage() {
		if (this.mNeedNextPage)
			this.mPage = (1 + this.mPage);
	}

}
*/